package com.designPattern.javaSupport;

import java.util.Observable;

/**
 * 继承Observable实现可观察者
 */
public class WeatherData extends Observable {
	
	private float temperature;//温度
	private float humidity;//湿度
	private float pressure;//气压
	
	public WeatherData() {
		super();
	}

	/**
	 * 提供观察者获取数据的方法
	 * @return
	 */
	public float getTemperature() {
		return temperature;
	}
	public float getHumidity() {
		return humidity;
	}
	public float getPressure() {
		return pressure;
	}
	
	/**
	 * 通知观察者
	 */
	public void measurementsChanged(){
		setChanged();
		notifyObservers();
	}
	
	/**
	 * 被观察者更新数据
	 * @param temperature
	 * @param humidity
	 * @param pressure
	 */
	public void setMeasurements(float temperature, float humidity, float pressure){
		this.temperature = temperature;
		this.humidity = humidity;
		this.pressure = pressure;
		measurementsChanged();
	}
}
